ParcelTrack API

(0 reviews)

Binary Signature Decode Samples

Tracking events may include an encoded signature. The following code samples below can be used to decode the signature image.

C# Sample


namespace SigDisplay
{
    public partial class SigDisplay : Form
    {
        public SigDisplay()
        {
            InitializeComponent();
        }

        private void btnConvert_Click(object sender, EventArgs e)
        {
            // convert the original XML data into binary
            byte[] bin = System.Convert.FromBase64String(txtEncoded.Text);
            lblSize.Text = bin.Length.ToString() + " bytes";

            // construct a string version of the binary data
            string s = "";
            bool b = false;

            // create a graphics image of the binary data
            Bitmap img = new Bitmap(pb.Width, pb.Height);
            Graphics g = Graphics.FromImage(img);
            g.Clear(Color.White);
            Pen p = new Pen(Color.Black, 1);

            // run the binary data, capturing the pairs and writing to image and string
            Point p1 = new Point();
            Point p0 = new Point();
            bool st = false;
            for (int i = 0; i < bin.Length; i++)
            {
                if (bin[i] == 255)              // its the pen-down trigger
                {
                    if (i > 0)
                        s += "\r\n";            // start as a new line
                    b = false;                  // and mark as a new pen
                    st = false;
                }
                else
                {
                    if (b)                      // save the X co-ord
                        p1.X = bin[i];
                    else
                    {
                        p1.Y = bin[i];          // save the Y co-ord
                        if (st)                 // draw a line if we have a start and an end
                            g.DrawLine(p, p0, p1);

                        p0 = p1;                // remember this point as the start of the next point
                        st = true;              // have got a start co-ordinate for the line now
                    }
                }
                s += bin[i].ToString() + (b ? "," : " ");
                b = !b;                         // getting the 'other' byte
            }
            // and update the form
            txtDecoded.Text = s;
            pb.Image = img;
        }
    }
}


Reviews